package com.xq.shop.controller.user;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.xq.shop.po.ProductScore;
import com.xq.shop.po.User;
import com.xq.shop.service.user.IBaseService;
import com.xq.shop.service.user.IProductScoreService;
import com.xq.shop.util.Const;
import com.xq.shop.util.UserServiceFactory;

@Controller
@RequestMapping("/user/")
public class ScoreCtrl extends BaseCtrl<ProductScore>{

	private IProductScoreService scoreService = UserServiceFactory.getScoreService();
	
	@Override
	public IBaseService<ProductScore> getService() {
		return scoreService;
	}

	@RequestMapping("score_save")
	public void save(ProductScore score, HttpServletRequest request, HttpServletResponse response){
		User user = (User) request.getSession().getAttribute(Const.User_Session);
		score.setUser_id(user.getId());
		ProductScore instance = scoreService.get(user.getId(), score.getOrder_id(), score.getProduct_id());
		if(instance != null){
			score.setId(instance.getId());
			score.setModify_date(new Date(System.currentTimeMillis()));
		}
		scoreService.saveOrUpdate(score);
	}
}
